//
//  AddStudentViewController.m
//  08-UITableViewHomeWork
//
//  Created by 曹曹 on 16/7/25.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "AddStudentViewController.h"

@interface AddStudentViewController ()
@property (nonatomic, strong) UITextField *name;
@property (nonatomic, strong) UITextField *age;
@property (nonatomic, strong) UITextField *gender;
@property (nonatomic, strong) UITextField *phoneNumber;
@property (nonatomic, strong) NSMutableDictionary *diction;
@end

@implementation AddStudentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 背景图片
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageView.image = [UIImage imageNamed:@"guidePage_03"];
    [self.view addSubview:imageView];
    // label
    UILabel *nameLeft = [[UILabel alloc] initWithFrame:CGRectMake(100, 170, 60, 44)];
    UILabel *ageLeft = [[UILabel alloc] initWithFrame:CGRectMake(100, 220, 60, 44)];
    UILabel *genderLeft = [[UILabel alloc] initWithFrame:CGRectMake(100, 270, 60, 44)];
    UILabel *phoneNumberLeft = [[UILabel alloc] initWithFrame:CGRectMake(100, 320, 60, 44)];
    // textField
    self.name = [[UITextField alloc] initWithFrame:CGRectMake(200, 170, 200, 44)];
    self.age = [[UITextField alloc] initWithFrame:CGRectMake(200, 220, 200, 44)];
    self.gender = [[UITextField alloc] initWithFrame:CGRectMake(200, 270, 200, 44)];
    self.phoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(200, 320, 200, 44)];
    [self.view addSubview:nameLeft];
    [self.view addSubview:ageLeft];
    [self.view addSubview:genderLeft];
    [self.view addSubview:phoneNumberLeft];
    nameLeft.text = @"姓名:";
    ageLeft.text = @"年龄:";
    genderLeft.text = @"性别:";
    phoneNumberLeft.text = @"电话:";
    _name.placeholder = @"请输入姓名";
    _age.placeholder = @"请输入年龄";
    _gender.placeholder = @"请输入性别";
    _phoneNumber.placeholder = @"请输入电话";
    [self.view addSubview:_name];
    [self.view addSubview:_age];
    [self.view addSubview:_gender];
    [self.view addSubview:_phoneNumber];
    // 保存按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(back:)];
}
// 保存按钮点击事件
- (void)back:(UIBarButtonItem *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(addStudentWithDictionary:)]) {
        NSNumber *ageNumber = [[[NSNumberFormatter alloc] init] numberFromString:_age.text];
        self.diction = [NSMutableDictionary dictionaryWithObjectsAndKeys:_name.text, @"name", ageNumber, @"age", _gender.text, @"gender", _phoneNumber.text, @"phoneNumber", nil];
        [self.delegate addStudentWithDictionary:_diction];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
